<?php

class Product extends BaseModel 
{
    /**
     * Returns the static model of the specified AR class.
     * @return CActiveRecord the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'product';
    }

    public function rules()
    {
        return array(
            array('product_name', 'required', 'message'=>'{attribute} 不能为空'),
            array('product_name', 'unique'), 
        );
    }

    public function attributeLabels()
    {
        return array(
            'product_id' => '编号',
            'product_name' => '产品线名称',
        );
    }

    public static function listItems() 
    {
        $products = Product::model()->findAll();

        $items = array();
        foreach($products as $product) {
            $items[$product['product_id']] = $product['product_name'];
        }
        return $items;
    }
}
